package dynamic.mybatisplus.core.injector.methods;



import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import dynamic.DynamicEntity;
import dynamic.ibatis.mapping.DMappedStatement;
import dynamic.ibatis.mapping.DSqlSource;
import dynamic.metadata.DTableInfo;
import dynamic.metadata.EntityClass;
import dynamic.mybatisplus.core.injector.DAbstractMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 查询满足条件所有数据（并翻页）
 *
 * @author hubin
 * @since 2018-04-06
 * @deprecated 3.5.3.2 {@link BaseMapper#selectList(IPage, Wrapper)}
 */
@Deprecated
public class DSelectPage extends DAbstractMethod {

    public DSelectPage() {
        this(SqlMethod.SELECT_PAGE.getMethod());
    }

    /**
     * @since 3.5.0
     * @param name 方法名
     */
    public DSelectPage(String name) {
        super(name);
    }

    @Override
    public DMappedStatement injectMappedStatement(Class<?> mapperClass, EntityClass modelClass, DTableInfo tableInfo) {
        SqlMethod sqlMethod = SqlMethod.SELECT_PAGE;
        String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true),
                tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo), sqlOrderBy(tableInfo), sqlComment());
        DSqlSource sqlSource = super.createSqlSource(configuration, sql, DynamicEntity.class);
        return this.addSelectMappedStatementForTable(mapperClass, methodName, sqlSource, tableInfo);
    }
}
